﻿using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace WebPattern.Core.Validators
{
    public static class StaticValidators
    {
        /// <summary>
        /// Emails the validator.
        /// </summary>
        /// <param name="emailToValidate">The email to validate.</param>
        /// <returns>True - email is valid else False.</returns>
        /// <remarks></remarks>
        public static bool EmailValidator(string emailToValidate)
        {
            return Regex.IsMatch(emailToValidate, @"^\s*([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4}))\s*$");
        }

        /// <summary>
        /// Usernames the validator.
        /// </summary>
        /// <param name="usernameToValidate">The username to validate.</param>
        /// <returns>True - username is valid else False.</returns>
        /// <remarks></remarks>
        public static bool UsernameValidator(string usernameToValidate)
        {
            return !string.IsNullOrWhiteSpace(usernameToValidate);
        }

        /// <summary>
        /// Roles the name validator.
        /// </summary>
        /// <param name="roleNameToValidate">The role name to validate.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static bool RoleNameValidator(string roleNameToValidate)
        {
            bool rValue = true;

            if (string.IsNullOrWhiteSpace(roleNameToValidate)) rValue = false;
            if (roleNameToValidate.Contains(',')) rValue = false;

            return rValue;
        }
    }
}
